from neo4j import GraphDatabase

import os
from dotenv import load_dotenv

load_dotenv()

class Neo4jDriver:

    def __init__(self):
        url, user, password = os.getenv('NEO4J_URL'), os.getenv('NEO4J_USER'), os.getenv('NEO4J_PASS')
        database = os.getenv("NEO4J_DATABASE") or "neo4j"

        self.driver = GraphDatabase.driver(url, auth=(user, password), database=database)
        self.driver.verify_connectivity()

    def execute(self, query):
        records, summary, keys = self.driver.execute_query(query)
        return records, summary, keys

    def __del__(self):
        if hasattr(self, 'driver') and self.driver:
            self.driver.close()
            
if __name__ == '__main__':

    neo4j_driver = Neo4jDriver()
    records, summary, keys = neo4j_driver.execute('match (e:User)-[r]->(e2) return * limit 10')

    for record in records:
        print(record.data())
